package logic

import (
	"context"
	"wechat/personrpc/personrpc"

	"wechat/api/internal/svc"
	"wechat/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateLogic) Update(req *types.UpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.PersonRpc.Update(l.ctx, &personrpc.UpdateRequest{
		Image:   req.Image,
		Name:    req.Name,
		UserId:  req.UserId,
		Info:    req.Info,
		Address: req.Address,
		Id:      req.Id,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Code:    200,
		Data:    update,
	}, nil
}
